#!/bin/bash

# 检查服务状态脚本

echo "=========================================="
echo "服务状态检查"
echo "=========================================="
echo ""

# 检查Nacos
echo "1. 检查Nacos (端口8848)..."
if lsof -Pi :8848 -sTCP:LISTEN -t >/dev/null 2>&1 ; then
    echo "   ✅ Nacos 正在运行"
else
    echo "   ❌ Nacos 未运行"
fi
echo ""

# 检查Gateway
echo "2. 检查Gateway (端口8080)..."
if lsof -Pi :8080 -sTCP:LISTEN -t >/dev/null 2>&1 ; then
    echo "   ✅ Gateway 正在运行"
else
    echo "   ❌ Gateway 未运行"
fi
echo ""

# 检查user-service
echo "3. 检查user-service (端口8082)..."
if lsof -Pi :8082 -sTCP:LISTEN -t >/dev/null 2>&1 ; then
    echo "   ✅ user-service 正在运行"
else
    echo "   ❌ user-service 未运行"
    echo "   提示: 请在IDE中启动 UserApplication"
fi
echo ""

# 检查auth-service
echo "4. 检查auth-service (端口8081)..."
if lsof -Pi :8081 -sTCP:LISTEN -t >/dev/null 2>&1 ; then
    echo "   ✅ auth-service 正在运行"
else
    echo "   ❌ auth-service 未运行"
fi
echo ""

# 检查attendance-service
echo "5. 检查attendance-service (端口8083)..."
if lsof -Pi :8083 -sTCP:LISTEN -t >/dev/null 2>&1 ; then
    echo "   ✅ attendance-service 正在运行"
else
    echo "   ❌ attendance-service 未运行"
fi
echo ""

# 检查leave-service
echo "6. 检查leave-service (端口8084)..."
if lsof -Pi :8084 -sTCP:LISTEN -t >/dev/null 2>&1 ; then
    echo "   ✅ leave-service 正在运行"
else
    echo "   ❌ leave-service 未运行"
fi
echo ""

# 检查salary-service
echo "7. 检查salary-service (端口8085)..."
if lsof -Pi :8085 -sTCP:LISTEN -t >/dev/null 2>&1 ; then
    echo "   ✅ salary-service 正在运行"
else
    echo "   ❌ salary-service 未运行"
fi
echo ""

# 检查notification-service
echo "8. 检查notification-service (端口8086)..."
if lsof -Pi :8086 -sTCP:LISTEN -t >/dev/null 2>&1 ; then
    echo "   ✅ notification-service 正在运行"
else
    echo "   ❌ notification-service 未运行"
    echo "   提示: 请在IDE中启动 NotificationApplication"
fi
echo ""

echo "=========================================="
echo "如果服务未运行，请："
echo "1. 在IDE中启动对应的Application类"
echo "2. 确认服务注册到Nacos (http://localhost:8848/nacos)"
echo "3. 刷新前端页面重试"
echo ""
echo "注意：notification-service未运行不会影响主要功能，"
echo "      但会导致未读消息数量无法显示"
echo "=========================================="

